package com.jn.erp.wechat.staff.api.controller;

import com.jn.erp.common.core.result.AjaxResult;
import com.jn.erp.web.api.student.entity.dto.TStudentAppointmentDto;
import com.jn.erp.web.api.student.service.TStudentAppointmentService;
import com.jn.erp.wechat.common.api.controller.base.BaseWxAuthController;
import com.jn.erp.wechat.common.api.entity.dto.WxUserDto;
import com.jn.erp.wechat.core.WxTableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <pre>
 *  预约 试听 相关
 * </pre>
 *
 * @author sunjiyong
 * @since 2024/11/15 9:49
 */
@RestController
@RequestMapping("/wx/audition")
public class MpAuditionController extends BaseWxAuthController {


    @Autowired
    private TStudentAppointmentService tStudentAppointmentService;


    /**
     * 试听列表  /auditionCourse/auditionList
     */
    @GetMapping("/auditionList")
    public WxTableDataInfo auditionList(TStudentAppointmentDto tStudentAppointmentDto) {
        WxUserDto wxUser = getWxUser();
        tStudentAppointmentDto.setOrgId(wxUser.getOrgIdLong());
        startPage();
        List<TStudentAppointmentDto> list = tStudentAppointmentService.auditionList(tStudentAppointmentDto);
        return getWxDataTable(list);
    }



    /**
     * 开班试听   /auditionCourse/startClassAudition
     * @param tStudentAppointmentDto
     * @return
     */
    @PostMapping("/startClassAudition")
    public AjaxResult startClassAudition (@RequestBody TStudentAppointmentDto tStudentAppointmentDto) {
        WxUserDto wxUser = getWxUser();
        tStudentAppointmentDto.setOrgId(wxUser.getOrgIdLong());
        tStudentAppointmentService.startClassAudition(tStudentAppointmentDto);
        return success("新建课次成功");
    }


    /**
     取消试听  /auditionCourse/cancelAudition
     */

    @PostMapping("/cancelAudition")
    public AjaxResult cancelAudition (@RequestBody TStudentAppointmentDto tStudentAppointmentDto) {
        WxUserDto wxUser = getWxUser();
        // 机构id报读
        tStudentAppointmentDto.setOrgId(wxUser.getOrgIdLong());
        tStudentAppointmentService.cancelAudition(tStudentAppointmentDto);
        return success("取消试听成功");
    }
}
